package com.quzi.kettle.view;


import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.quzi.kettle.R;

/**
 */
public class ImageEditText extends LinearLayout {

	private View mainView;
	private Context mContext;

	private EditText edittext;
	private ImageView icon;
	private TextView info;
	
	private ImageEditorInterface handler;
	
	
	public ImageEditText(Context context) {
		this(context, null, 0);
	}

	public ImageEditText(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public ImageEditText(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);

		this.mContext = context;
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mainView = inflater.inflate(R.layout.image_edittext, this);
		
		edittext = (EditText) mainView.findViewById(R.id.edittext);
		icon = (ImageView) mainView.findViewById(R.id.img);
		info = (TextView) mainView.findViewById(R.id.info);
		
		info.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				if(handler != null)
				handler.onInfoTextClicked();
			}
		});
	}
	
	public EditText getEditText(){
		return edittext;
	}
	
	public void update_image(int image){
		icon.setImageResource(image);
	}

	public String getTextStr(){
		return edittext.getText().toString();
	}
	
	public void setText(String text){
		edittext.setText(text);
	}
	
	public void setHint(String hint){
		edittext.setHint(hint);
	}
	
	public void setInfoText(String str){
		if(!str.isEmpty()){
			info.setVisibility(View.VISIBLE);
			info.setText(str);
		}
	}
	
	public void setInfoClickListener(ImageEditorInterface handler){
		this.handler = handler;
	}
	
	
	public String getText(){
		return edittext.getText().toString();
	}
}
